<template>
    <div class="login">
        <h2>后台管理界面</h2>
        <el-input placeholder="请输入用户名" v-model="username"></el-input>

        <el-input type="password" placeholder="请输入密码" v-model="password"></el-input>

        <el-button @click="login">登陆</el-button>
    </div>
</template>

<script>
    import API_URI from '@/util/API/ApiUtil'
    export default{
        data(){
            return{
                username: '',
                password: '',
            }
        },
        created(){

        },
        methods:{
            login(){
                let username = this.username
                let password = this.password

                let data = {
                    username,
                    password
                }

                this.$axios.post(API_URI.LOGIN_ADMINISTRATOR, data)
                .then(res => {
                    if(res.code == 200){
                        this.$success("登陆成功")

                        sessionStorage.setItem("token", res.data.token)

                        this.$router.push({name: 'user'})
                    }
                    else{
                        this.$error(res.message)
                    }
                })
            }
        }
    }
</script>

<style scoped>
    .login{
        width:50%;
        margin:auto;

        padding:20px;
        text-align: center;;
    }

    .login .el-input{
        margin-bottom:10px;
    }
</style>